Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown gradually if not able to initialize display #11

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

seriyps
Copy link
Collaborator

@seriyps seriyps commented Oct 3, 2024

There was a bug in the display initialization code that caused SIGSEGV on attempt to render something (video or OSD) on the screen when either screen is not connected or or resolution is not set correctly.

This PR makes sure pixelpilot detects the initialization error earlier and shuts down gradually.

Before:

#
# OSD, no video, no display
#
(gdb) run
Starting program: /usr/local/bin/pixelpilot --osd --osd-elements video,wfbng --screen-mode 1280x720@60
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
PixelPilot Rockchip 0.10
ignoring unused connector 111
[New Thread 0xfffff552dfa0 (LWP 933)]
[New Thread 0xfffff4d2cfa0 (LWP 934)]
[New Thread 0xfffff452bfa0 (LWP 935)]
Changed prio for FRAME_THREAD to SCHED_FIFO:40
[New Thread 0xffffebffefa0 (LWP 936)]
[New Thread 0xfffff3d2afa0 (LWP 937)]
Starting mavlink thread...
[New Thread 0xfffff3529fa0 (LWP 938)]
/home/radxa/PixelPilot_rk/src/drm.c:126:28: runtime error: member access within null pointer of type 'struct drmModeObjectProperties'

Thread 7 "pixelpilot" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xfffff3529fa0 (LWP 938)]
0x0000aaaaaaac16a4 in set_drm_object_property (req=0x0, obj=0xaaaaaab5c6d0, name=0xaaaaaaaebe40 "CRTC_ID", value=0) at /home/radxa/PixelPilot_rk/src/drm.c:126
126             for (i = 0; i < obj->props->count_props; i++) {
(gdb) where
#0  0x0000aaaaaaac16a4 in set_drm_object_property (req=0x0, obj=0xaaaaaab5c6d0, name=0xaaaaaaaebe40 "CRTC_ID", value=0) at /home/radxa/PixelPilot_rk/src/drm.c:126
#1  0x0000aaaaaaac6340 in modeset_atomic_prepare_commit (fd=11, out=0xaaaaaab5c6d0, req=0x0, plane=0xaaaaaab5c7c0, fb_id=0, width=0, height=0, zpos=2) at /home/radxa/PixelPilot_rk/src/drm.c:582
#2  0x0000aaaaaaac603c in modeset_perform_modeset (fd=11, out=0xaaaaaab5c6d0, req=0x0, plane=0xaaaaaab5c7c0, fb_id=0, width=0, height=0, zpos=2) at /home/radxa/PixelPilot_rk/src/drm.c:555
#3  0x0000aaaaaaaca118 in __OSD_THREAD__ (param=0xaaaaaab214c0) at /home/radxa/PixelPilot_rk/src/osd.c:317
#4  0x0000fffff7cb8648 in start_thread (arg=0xfffff35298a0) at pthread_create.c:477
#5  0x0000fffff6b30c9c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

After this PR:

(gdb) run                                                                                             
Starting program: /usr/local/bin/pixelpilot --screen-mode 1280x720@60                                                                                                                                        
[Thread debugging using libthread_db enabled]                                                         
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".                                                                                                                                  
PixelPilot Rockchip 0.10                                                                                                                                                                                     
ignoring unused connector 111                                                                                                                                                                                
couldn't create any outputs                                                                           
cannot initialize display. Is display connected? Is --screen-mode correct?                                                                                                                                   
[Inferior 1 (process 837) exited with code 0377]                                                      
(gdb) q   

@seriyps
Copy link
Collaborator Author

seriyps commented Oct 3, 2024

Sidenote (writing it here because "issues" on github is not available):
UPD: see #13
I think in case none of the resolutions supported by connected monitor matches exactly the value of --screen-mode, I think it might be better to anyway select one of the resolutions that is the closest one to the requested one and use it instead of crashing?

Eg, if user requests --screen-mode 1920x1080@60 but the supported resolutions are

9 : 1920x1080@30
12 : 1920x1080@24
13 : 1600x1200@60
14 : 1680x1050@60
15 : 1280x1024@75
16 : 1280x1024@60
17 : 1152x864@75

pixelpilot should select the closest one, eg, 1920x1080@24.

The way heuristics may work is by finding the minimum of the abs( (mode_width - hdisplay) + (mode_height - hdisplay) + (mode_vrefresh - vrefresh) )

@luastoned
Copy link
Collaborator

LGTM, thanks.

@luastoned luastoned merged commit e070b64 into OpenIPC:master Oct 4, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants